﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using myUserManagement;

namespace POS
{
    public partial class frmLogin : Form
    {
        ghieUserManagement ghieUser = new ghieUserManagement();

        frmMain parent;
        public frmLogin(frmMain p)
        {
            parent = p;
            InitializeComponent();
            btnLogin.Click += new EventHandler(btnLogin_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);
        }

        void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("Are You sure want to Cancel?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                this.Close();
            }
            else
            {
                this.Show();

            }
        }

        void btnLogin_Click(object sender, EventArgs e)
        {
            ghieUser.connection();
            ghieUser.mylogin("SELECT * from tbluser WHERE fUsername = '" + txtUsername.Text + "' and fPassword = '" + this.txtPassword.Text + "'");
            if (ghieUser.tbl.Rows.Count > 0)
            {
                MessageBox.Show("Successful");
                string accesslevel = ghieUser.tbl.Rows[0]["flevel"].ToString();
                parent.manipulation(accesslevel);
                this.Close();
            }
            else
            {
                MessageBox.Show("Invalid Username or Password");
                txtUsername.Text = "";
                txtPassword.Text = "";
                txtUsername.Focus();

            }
            ghieUser.DBClose();
        }
    }
}
